<?php
/**
 * Created by PhpStorm.
 * User: lzhy@lzhy.me
 * Date: 2019/4/12 0012
 * Time: 14:32
 */
namespace app\admin\controller;

use app\admin\logic\Auth;
use think\facade\Cookie;
use think\facade\Request;
use think\facade\Session;

class Login extends Base
{
    public function index()
    {
        if(self::$userId){
            $this->redirect('index/index');
        }
        if(Request::isPost()){
            $username = Request::post('username');
            $password = Request::post('password');
            $remember = Request::post('remember');
            $loginErr = '请填写完整后再提交';
            if($username && $password){
                $loginErr = '登录失败，请重试';
                if(Auth::attempt($username,$password,$remember)){
                    $this->redirect('index/index');
                }
            }
            $this->assign('login_err',$loginErr);
        }
        return view();
    }

    public function logout()
    {
        Session::clear();
        Cookie::clear();
        $this->redirect('index');
    }
}